<?php
// No direct access
defined('_JEXEC') or die;
?>

			//select-join-table-1
			document.id('select-table-container').addEvent('change:relay(select.select-join-table-1)', function(){
				var fields = this.getNext('span.fields-container');
				changeFields(fields, this.get('value'), 1)
			});

			document.id('select-table-container').addEvent('change:relay(select.select-join-table-2)', function(){
				var fields = this.getNext('span.fields-container');
				changeFields(fields, this.get('value'), 2)
			});

			document.id('btn-join-table').addEvent('click', function(){
				var html = $('tmpl-join-fields').get('html');

				var tableRowObject = new Element('li', { html: html, 'class': 'join-table' });
				tableRowObject.inject($('tmpl-join-fields'), 'before');

				return false;
			});

			document.id('select-table-container').addEvent('click:relay(a.del-join-table)', function(){
				this.getParent().destroy();
				return false;
			});

			<?php foreach ($this->joins as $key => $join): ?>
			var fields_1_<?php echo $key; ?> = document.id('join_table_on_1_<?php echo $key; ?>').getNext('span.fields-container');
			changeFields(fields_1_<?php echo $key; ?>, document.id('join_table_on_1_<?php echo $key; ?>').get('value'), 1, '<?php echo $join->join_field_on_1; ?>')
			<?php endforeach; ?>

			<?php foreach ($this->joins as $key => $join): ?>
			var fields_2_<?php echo $key; ?> = document.id('join_table_on_2_<?php echo $key; ?>').getNext('span.fields-container');
			changeFields(fields_2_<?php echo $key; ?>, document.id('join_table_on_2_<?php echo $key; ?>').get('value'), 2, '<?php echo $join->join_field_on_2; ?>')
			<?php endforeach; ?>